/*
 * This is Melet, a salary slip designer. Feed it with data regarding to salary payment, prepare it for print through the graphical presentation, and you have it done.
 * Copyright (C) 2014, AFDiaX
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * This program is based on UMLet, a Free UML Tool for Fast UML Diagrams.
 * To contact the authors of UMLet visit https://code.google.com/p/umlet/people/list
 * To contact the authors of Melet visit https://gna.org/users/gabocze
 */
package com.baselet.element.old.activity;

import java.awt.Graphics2D;
import java.awt.Point;

import com.baselet.diagram.DiagramHandler;

public class PartActivity extends Activity {

	private int minwidth = (int) (120 * getZoom());
	private int height = (int) (20 * getZoom());

	public PartActivity(DiagramHandler handler, String label, Graphics2D g, String id) {
		super(handler, label, g, id == null ? label : id);
		setHeight(height);
	}

	@Override
	protected int getLeftWidth() {
		return super.getLeftWidth() > minwidth / 2 ? super.getLeftWidth() : minwidth / 2;
	}

	@Override
	protected int getRightWidth() {
		return super.getRightWidth() > minwidth / 2 ? super.getRightWidth() : minwidth / 2;
	}

	@Override
	public void paint() {
		Point cord = getPosition();
		int h = getHeight();
		label.paint();
		getGraphics().drawRoundRect(cord.x - getLeftWidth(), cord.y - h / 2, getWidth(), h, (int) (20 * getZoom()), (int) (20 * getZoom()));
		getGraphics().drawRoundRect(cord.x - minwidth / 4, cord.y + h / 2 - height + (int) (5 * getZoom()), (int) (30 * getZoom()), (int) (10 * getZoom()), (int) (10 * getZoom()), (int) (10 * getZoom()));
		getGraphics().drawRoundRect(cord.x + (int) (15 * getZoom()), cord.y + h / 2 - height + (int) (5 * getZoom()), (int) (30 * getZoom()), (int) (10 * getZoom()), (int) (10 * getZoom()), (int) (10 * getZoom()));
		int x1 = cord.x - minwidth / 4 + (int) (30 * getZoom());
		int x2 = cord.x + (int) (15 * getZoom());
		int y = cord.y + h / 2 - height / 2;
		getGraphics().drawLine(x1, y, x2, y);
		getGraphics().drawLine(x2, y, x2 - (int) (3 * getZoom()), y - (int) (2 * getZoom()));
		getGraphics().drawLine(x2, y, x2 - (int) (3 * getZoom()), y + (int) (2 * getZoom()));
	}

	@Override
	public void setY(int y) {
		super.setY(y);
		label.setY(y - height / 2);
	}
}
